<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>错误和异常处理 | MXY 1.0版Python整理</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../../home/8.面向对象/7.模块和包.html" />
    
    
    <link rel="prev" href="../../home/8.面向对象/5.抽象类.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="8.6"
        data-chapter-title="错误和异常处理"
        data-filepath="home/8.面向对象/6.错误和异常处理.md"
        data-basepath="../.."
        data-revision="Mon Oct 22 2018 08:32:35 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        MXY整理版Python基础
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> Python的安装和简介</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="home/1.Python的安装和简介/1.python基础知识.html">
            
                
                    <a href="../../home/1.Python的安装和简介/1.python基础知识.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        Python的基础知识
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="home/1.Python的安装和简介/2.python的安装及版本检测.html">
            
                
                    <a href="../../home/1.Python的安装和简介/2.python的安装及版本检测.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        Python安装及版本检测
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="home/1.Python的安装和简介/3.第一个python程序.html">
            
                
                    <a href="../../home/1.Python的安装和简介/3.第一个python程序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        第一个Python程序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" >
            
            <span><b>2.</b> Python的基本语法</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="home/2.Python的基本语法/1.注释及语句分类.html">
            
                
                    <a href="../../home/2.Python的基本语法/1.注释及语句分类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        注释及语句分类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="home/2.Python的基本语法/2.命名方式和关键字.html">
            
                
                    <a href="../../home/2.Python的基本语法/2.命名方式和关键字.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        命名方式和关键字
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> Python的变量及数据类型</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="home/3.变量和数据类型/1.变量.html">
            
                
                    <a href="../../home/3.变量和数据类型/1.变量.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        变量
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="home/3.变量和数据类型/2.数据类型.html">
            
                
                    <a href="../../home/3.变量和数据类型/2.数据类型.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        数据类型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="home/3.变量和数据类型/3.数据类型转换.html">
            
                
                    <a href="../../home/3.变量和数据类型/3.数据类型转换.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="home/3.变量和数据类型/4.运算和运算符.html">
            
                
                    <a href="../../home/3.变量和数据类型/4.运算和运算符.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        数据类型转换
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> Python的流程控制</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="home/4.流程控制/1.顺序结构和分支结构.html">
            
                
                    <a href="../../home/4.流程控制/1.顺序结构和分支结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        顺序结构和分支结构
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="home/4.流程控制/2.循环结构.html">
            
                
                    <a href="../../home/4.流程控制/2.循环结构.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        循环结构
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" >
            
            <span><b>5.</b> 函数及作用域</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="home/5.函数及作用域/1.函数.html">
            
                
                    <a href="../../home/5.函数及作用域/1.函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="home/5.函数及作用域/2.函数文档.html">
            
                
                    <a href="../../home/5.函数及作用域/2.函数文档.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        函数文档
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="home/5.函数及作用域/3.变量的作用域.html">
            
                
                    <a href="../../home/5.函数及作用域/3.变量的作用域.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        变量的作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.4" data-path="home/5.函数及作用域/4.内部函数和闭包操作.html">
            
                
                    <a href="../../home/5.函数及作用域/4.内部函数和闭包操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        内部函数和闭包操作
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="home/5.函数及作用域/5.lambda表达式.html">
            
                
                    <a href="../../home/5.函数及作用域/5.lambda表达式.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        lambda表达式
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="home/5.函数及作用域/6.高阶函数.html">
            
                
                    <a href="../../home/5.函数及作用域/6.高阶函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        高阶函数
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" >
            
            <span><b>6.</b> 内置函数及操作</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="home/6.内置函数及操作/1.字符串相关.html">
            
                
                    <a href="../../home/6.内置函数及操作/1.字符串相关.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        字符串相关
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="home/6.内置函数及操作/2.format格式字符串.html">
            
                
                    <a href="../../home/6.内置函数及操作/2.format格式字符串.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        format格式字符串
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="home/6.内置函数及操作/3.内建函数.html">
            
                
                    <a href="../../home/6.内置函数及操作/3.内建函数.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="home/6.内置函数及操作/4.列表.html">
            
                
                    <a href="../../home/6.内置函数及操作/4.列表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        列表
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="home/6.内置函数及操作/5.元组.html">
            
                
                    <a href="../../home/6.内置函数及操作/5.元组.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        元组
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="home/6.内置函数及操作/6.字典.html">
            
                
                    <a href="../../home/6.内置函数及操作/6.字典.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        字典
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.7" data-path="home/6.内置函数及操作/7.集合.html">
            
                
                    <a href="../../home/6.内置函数及操作/7.集合.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.7.</b>
                        
                        集合
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.8" data-path="home/6.内置函数及操作/8.文件操作.html">
            
                
                    <a href="../../home/6.内置函数及操作/8.文件操作.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.8.</b>
                        
                        文件操作
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" >
            
            <span><b>7.</b> 常用的模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="home/7.常用模块/1.String模块.html">
            
                
                    <a href="../../home/7.常用模块/1.String模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        String模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="home/7.常用模块/2.math模块.html">
            
                
                    <a href="../../home/7.常用模块/2.math模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        math模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="home/7.常用模块/3.OS模块.html">
            
                
                    <a href="../../home/7.常用模块/3.OS模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        OS模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="home/7.常用模块/4.zipfile模块.html">
            
                
                    <a href="../../home/7.常用模块/4.zipfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        zipfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="home/7.常用模块/5.tarfile模块.html">
            
                
                    <a href="../../home/7.常用模块/5.tarfile模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        tarfile模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.6" data-path="home/7.常用模块/6.shutil模块.html">
            
                
                    <a href="../../home/7.常用模块/6.shutil模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.6.</b>
                        
                        shutil模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.7" data-path="home/7.常用模块/7.时间相关模块.html">
            
                
                    <a href="../../home/7.常用模块/7.时间相关模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.7.</b>
                        
                        时间相关模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="8" >
            
            <span><b>8.</b> 面向对象</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="8.1" data-path="home/8.面向对象/1.类和对象-上.html">
            
                
                    <a href="../../home/8.面向对象/1.类和对象-上.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.1.</b>
                        
                        类和对象-上
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.2" data-path="home/8.面向对象/2.类和对象-下.html">
            
                
                    <a href="../../home/8.面向对象/2.类和对象-下.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.2.</b>
                        
                        类和对象-下
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.3" data-path="home/8.面向对象/3.魔术方法.html">
            
                
                    <a href="../../home/8.面向对象/3.魔术方法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.3.</b>
                        
                        魔术方法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.4" data-path="home/8.面向对象/4.装饰器.html">
            
                
                    <a href="../../home/8.面向对象/4.装饰器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.4.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.5" data-path="home/8.面向对象/5.抽象类.html">
            
                
                    <a href="../../home/8.面向对象/5.抽象类.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.5.</b>
                        
                        抽象类
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="8.6" data-path="home/8.面向对象/6.错误和异常处理.html">
            
                
                    <a href="../../home/8.面向对象/6.错误和异常处理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.6.</b>
                        
                        错误和异常处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="8.7" data-path="home/8.面向对象/7.模块和包.html">
            
                
                    <a href="../../home/8.面向对象/7.模块和包.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>8.7.</b>
                        
                        模块和包
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="9" >
            
            <span><b>9.</b> tkinter模块</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="9.1" data-path="home/9.tkinter模块/tkinter模块.html">
            
                
                    <a href="../../home/9.tkinter模块/tkinter模块.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>9.1.</b>
                        
                        tkinter模块
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="10" data-path="home/10.网络编程/1.网络编程.html">
            
                
                    <a href="../../home/10.网络编程/1.网络编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.</b>
                        
                        网络编程
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="10.1" data-path="home/10.网络编程/2.TCP编程.html">
            
                
                    <a href="../../home/10.网络编程/2.TCP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.1.</b>
                        
                        TCP编程
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="10.2" data-path="home/10.网络编程/3.UDP编程.html">
            
                
                    <a href="../../home/10.网络编程/3.UDP编程.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>10.2.</b>
                        
                        UDP编程
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="11" data-path="home/11.多任务/多任务原理.html">
            
                
                    <a href="../../home/11.多任务/多任务原理.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.</b>
                        
                        多任务
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="11.1" data-path="home/11.多任务/1.多进程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/1.多进程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.1.</b>
                        
                        多进程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.2" data-path="home/11.多任务/2.多线程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/2.多线程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.2.</b>
                        
                        多线程实现多任务
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="11.3" data-path="home/11.多任务/3.协程实现多任务.html">
            
                
                    <a href="../../home/11.多任务/3.协程实现多任务.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>11.3.</b>
                        
                        协程实现多任务
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="12" >
            
            <span><b>12.</b> Python实战项目</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="12.1" data-path="home/12.Python实战项目/1.简易计算器.html">
            
                
                    <a href="../../home/12.Python实战项目/1.简易计算器.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.1.</b>
                        
                        简易计算器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.2" data-path="home/12.Python实战项目/2.自动售货机.html">
            
                
                    <a href="../../home/12.Python实战项目/2.自动售货机.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.2.</b>
                        
                        自动售货机
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.3" data-path="home/12.Python实战项目/3.银行项目.html">
            
                
                    <a href="../../home/12.Python实战项目/3.银行项目.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.3.</b>
                        
                        银行项目
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.4" data-path="home/12.Python实战项目/4.简单的登录注册.html">
            
                
                    <a href="../../home/12.Python实战项目/4.简单的登录注册.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.4.</b>
                        
                        简单的登录注册
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.5" data-path="home/12.Python实战项目/5.双色球.html">
            
                
                    <a href="../../home/12.Python实战项目/5.双色球.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.5.</b>
                        
                        双色球
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.6" data-path="home/12.Python实战项目/6.python垃圾回收机制.html">
            
                
                    <a href="../../home/12.Python实战项目/6.python垃圾回收机制.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.6.</b>
                        
                        python垃圾回收机制
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.7" data-path="home/12.Python实战项目/7.turtle画国旗.html">
            
                
                    <a href="../../home/12.Python实战项目/7.turtle画国旗.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.7.</b>
                        
                        turtle画国旗
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.8" data-path="home/12.Python实战项目/8.turtle画小猪佩奇.html">
            
                
                    <a href="../../home/12.Python实战项目/8.turtle画小猪佩奇.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.8.</b>
                        
                        turtle画小猪佩奇
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="12.9" data-path="home/12.Python实战项目/9.turtle画个表.html">
            
                
                    <a href="../../home/12.Python实战项目/9.turtle画个表.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>12.9.</b>
                        
                        turtle画个表
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../../" >MXY 1.0版Python整理</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x9519;&#x8BEF;&#x548C;&#x5F02;&#x5E38;&#x5904;&#x7406;">&#x9519;&#x8BEF;&#x548C;&#x5F02;&#x5E38;&#x5904;&#x7406;</h1>
<hr>
<blockquote>
<p>&#x5728;python&#x4E2D;&#x4E00;&#x5171;&#x6709;2&#x79CD;&#x9519;&#x8BEF;&#xFF1A;&#x4E00;&#x79CD;&#x662F;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#xFF0C;&#x53E6;&#x5916;&#x4E00;&#x79CD;&#x662F;&#x5F02;&#x5E38;&#x3002;</p>
</blockquote>
<ul>
<li><h3 id="&#x8BED;&#x6CD5;&#x9519;&#x8BEF;">&#x8BED;&#x6CD5;&#x9519;&#x8BEF;</h3>
<pre><code class="lang-py">  &#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#x4E5F;&#x53EB;&#x505A;&#x89E3;&#x6790;&#x9519;&#x8BEF;&#xFF0C;&#x662F;&#x6307;python&#x65E0;&#x6CD5;&#x6B63;&#x786E;&#x7684;&#x8BC6;&#x522B;&#x4EE3;&#x7801;&#x7684;&#x9020;&#x6210;&#x7684;&#x3002;
  &#x6839;&#x672C;&#x539F;&#x56E0;&#x5728;&#x4E8E;&#x4EBA;&#x7684;&#x884C;&#x4E3A;&#xFF1A;&#x624B;&#x6B8B;&#xFF0C;&#x8111;&#x6B8B;&#x548C;&#x773C;&#x6B8B;&#x7684;&#x884C;&#x4E3A;&#x3002;

  &#x89E3;&#x51B3;&#x65B9;&#x6CD5;&#xFF1A;&#x6309;&#x7167;&#x6B63;&#x786E;&#x7684;&#x8BED;&#x6CD5;&#x8FDB;&#x884C;&#x4E66;&#x5199;&#x5C31;&#x6CA1;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x4E86;&#xFF01;
</code></pre>
</li>
<li><h3 id="&#x5F02;&#x5E38;">&#x5F02;&#x5E38;</h3>
<pre><code class="lang-py">  &#x5F02;&#x5E38;&#x662F;&#x6307;&#x5728;&#x8BED;&#x6CD5;&#x6B63;&#x786E;&#x7684;&#x524D;&#x63D0;&#x4E0B;&#xFF0C;&#x7A0B;&#x5E8F;&#x7684;&#x62A5;&#x9519;&#x5C31;&#x662F;&#x5F02;&#x5E38;&#x3002;

  &#x5B83;&#x662F;&#x5728;&#x7A0B;&#x5E8F;&#x5F02;&#x5E38;&#x65F6;&#x5355;&#x72EC;&#x5B58;&#x5728;&#x7684;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x83B7;&#x53D6;&#x6216;&#x5176;&#x4ED6;&#x64CD;&#x4F5C;
</code></pre>
</li>
<li><h3 id="&#x5F02;&#x5E38;&#x7684;&#x5206;&#x7C7B;">&#x5F02;&#x5E38;&#x7684;&#x5206;&#x7C7B;</h3>
<pre><code class="lang-py">  AssertError               &#x65AD;&#x8A00;&#x8BED;&#x53E5;&#xFF08;<span class="hljs-keyword">assert</span>&#xFF09;&#x5931;&#x8D25;
  AttributeError            &#x5C1D;&#x8BD5;&#x8BBF;&#x95EE;&#x672A;&#x77E5;&#x7684;&#x5BF9;&#x8C61;&#x5C5E;&#x6027;
  EOFError                  &#x7528;&#x6237;&#x8F93;&#x5165;&#x6587;&#x4EF6;&#x672B;&#x5C3E;&#x6807;&#x5FD7;EOF&#xFF08;Ctrl+d&#xFF09;
  FloatingPointError        &#x6D6E;&#x70B9;&#x8BA1;&#x7B97;&#x9519;&#x8BEF;
  GeneratorExit             generator.close()&#x65B9;&#x6CD5;&#x88AB;&#x8C03;&#x7528;&#x7684;&#x65F6;&#x5019;
  ImportError               &#x5BFC;&#x5165;&#x6A21;&#x5757;&#x5931;&#x8D25;&#x7684;&#x65F6;&#x5019;
  IndexError                &#x7D22;&#x5F15;&#x8D85;&#x51FA;&#x5E8F;&#x5217;&#x7684;&#x8303;&#x56F4;
  KeyError                  &#x5B57;&#x5178;&#x4E2D;&#x67E5;&#x627E;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x5173;&#x952E;&#x5B57;
  KeyboardInterrupt         &#x7528;&#x6237;&#x8F93;&#x5165;&#x4E2D;&#x65AD;&#x952E;&#xFF08;Ctrl+c&#xFF09;
  MemoryError               &#x5185;&#x5B58;&#x6EA2;&#x51FA;&#xFF08;&#x53EF;&#x901A;&#x8FC7;&#x5220;&#x9664;&#x5BF9;&#x8C61;&#x91CA;&#x653E;&#x5185;&#x5B58;&#xFF09;
  NameError                 &#x5C1D;&#x8BD5;&#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x53D8;&#x91CF;
  NotImplementedError       &#x5C1A;&#x672A;&#x5B9E;&#x73B0;&#x7684;&#x65B9;&#x6CD5;
  OSError                   &#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4EA7;&#x751F;&#x7684;&#x5F02;&#x5E38;&#xFF08;&#x4F8B;&#x5982;&#x6253;&#x5F00;&#x4E00;&#x4E2A;&#x4E0D;&#x5B58;&#x5728;&#x7684;&#x6587;&#x4EF6;&#xFF09;
  OverflowError             &#x6570;&#x503C;&#x8FD0;&#x7B97;&#x8D85;&#x51FA;&#x6700;&#x5927;&#x9650;&#x5236;
  ReferenceError            &#x5F31;&#x5F15;&#x7528;&#xFF08;weak reference&#xFF09;&#x8BD5;&#x56FE;&#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x5DF2;&#x7ECF;&#x88AB;&#x5783;&#x573E;&#x56DE;&#x6536;&#x673A;&#x5236;&#x56DE;&#x6536;&#x4E86;&#x7684;&#x5BF9;&#x8C61;
  RuntimeError              &#x4E00;&#x822C;&#x7684;&#x8FD0;&#x884C;&#x65F6;&#x9519;&#x8BEF;
  StopIteration             &#x8FED;&#x4EE3;&#x5668;&#x6CA1;&#x6709;&#x66F4;&#x591A;&#x7684;&#x503C;
  SyntaxError               Python&#x7684;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;
  IndentationError          &#x7F29;&#x8FDB;&#x9519;&#x8BEF;
  TabError                  Tab&#x548C;&#x7A7A;&#x683C;&#x6DF7;&#x5408;&#x4F7F;&#x7528;
  SystemError               Python&#x7F16;&#x8BD1;&#x5668;&#x7CFB;&#x7EDF;&#x9519;&#x8BEF;
  SystemExit                Python&#x7F16;&#x8BD1;&#x5668;&#x8FDB;&#x7A0B;&#x88AB;&#x5173;&#x95ED;
  TypeError                 &#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x95F4;&#x7684;&#x65E0;&#x6548;&#x64CD;&#x4F5C;
  UnboundLocalError         &#x8BBF;&#x95EE;&#x4E00;&#x4E2A;&#x672A;&#x521D;&#x59CB;&#x5316;&#x7684;&#x672C;&#x5730;&#x53D8;&#x91CF;&#xFF08;NameError&#x7684;&#x5B50;&#x7C7B;&#xFF09;
  UnicodeError              Unicode&#x76F8;&#x5173;&#x7684;&#x9519;&#x8BEF;&#xFF08;ValueError&#x7684;&#x5B50;&#x7C7B;&#xFF09;
  UnicodeEncodeError        Unicode&#x7F16;&#x7801;&#x65F6;&#x7684;&#x9519;&#x8BEF;&#xFF08;UnicodeError&#x7684;&#x5B50;&#x7C7B;&#xFF09;
  UnicodeDecodeError        Unicode&#x89E3;&#x7801;&#x65F6;&#x7684;&#x9519;&#x8BEF;&#xFF08;UnicodeError&#x7684;&#x5B50;&#x7C7B;&#xFF09;
  UnicodeTranslateError     Unicode&#x8F6C;&#x6362;&#x65F6;&#x7684;&#x9519;&#x8BEF;&#xFF08;UnicodeError&#x7684;&#x5B50;&#x7C7B;&#xFF09;
  ValueError                &#x4F20;&#x5165;&#x65E0;&#x6548;&#x7684;&#x53C2;&#x6570;
  ZeroDivisionError         &#x9664;&#x6570;&#x4E3A;&#x96F6;
</code></pre>
</li>
</ul>
<hr>
<h1 id="&#x5E38;&#x89C1;&#x7684;&#x9519;&#x8BEF;&#x64CD;&#x4F5C;&#xFF1A;">&#x5E38;&#x89C1;&#x7684;&#x9519;&#x8BEF;&#x64CD;&#x4F5C;&#xFF1A;</h1>
<ul>
<li><h3 id="indexerror-&#x7D22;&#x5F15;&#x9519;&#x8BEF;">IndexError &#x7D22;&#x5F15;&#x9519;&#x8BEF;</h3>
<pre><code class="lang-py">  lists = [<span class="hljs-number">1</span>,<span class="hljs-number">3</span>,<span class="hljs-number">6</span>]
  print(lists[<span class="hljs-number">3</span>])
</code></pre>
</li>
<li><h3 id="keyerror-&#x952E;&#x4E0D;&#x5B58;&#x5728;">KeyError &#x952E;&#x4E0D;&#x5B58;&#x5728;</h3>
<pre><code class="lang-py">  dicts = {<span class="hljs-string">&apos;gp&apos;</span>:<span class="hljs-string">&apos;&#x9AD8;&#x5761;&apos;</span>,<span class="hljs-string">&apos;cr&apos;</span>:<span class="hljs-string">&apos;&#x66F9;&#x777F;&apos;</span>,<span class="hljs-string">&apos;tw&apos;</span>:<span class="hljs-string">&apos;&#x5510;&#x4F1F;&apos;</span>}
  print(dicts[<span class="hljs-string">&apos;zj&apos;</span>])
</code></pre>
</li>
<li><h3 id="nameerror-&#x53D8;&#x91CF;&#x4E0D;&#x5B58;&#x5728;">nameError &#x53D8;&#x91CF;&#x4E0D;&#x5B58;&#x5728;</h3>
<pre><code class="lang-py">  print(ch)
</code></pre>
</li>
<li><h3 id="asserterror-&#x65AD;&#x8A00;&#x9519;&#x8BEF;">AssertError &#x65AD;&#x8A00;&#x9519;&#x8BEF;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span>&gt;<span class="hljs-number">0</span>
  <span class="hljs-keyword">assert</span> <span class="hljs-number">3</span>&gt;<span class="hljs-number">5</span>
</code></pre>
</li>
<li><h3 id="indentationerror&#x7F29;&#x8FDB;&#x9519;&#x8BEF;">IndentationError&#x7F29;&#x8FDB;&#x9519;&#x8BEF;</h3>
<pre><code class="lang-py">  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">myfunc</span><span class="hljs-params">()</span>:</span>
      print(<span class="hljs-string">&apos;&#x773C;&#x6B8B;&apos;</span>)
     print(<span class="hljs-string">&apos;&#x773C;&#x6B8B;&apos;</span>)
</code></pre>
</li>
</ul>
<hr>
<h1 id="&#x9519;&#x8BEF;&#x5F02;&#x5E38;&#x5904;&#x7406;">&#x9519;&#x8BEF;&#x5F02;&#x5E38;&#x5904;&#x7406;</h1>
<ul>
<li><h3 id="&#x9519;&#x8BEF;&#x5F02;&#x5E38;&#x5904;&#x7406;">&#x9519;&#x8BEF;&#x5F02;&#x5E38;&#x5904;&#x7406;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">try</span>:
      <span class="hljs-comment"># &#x5C1D;&#x8BD5;&#x5B9E;&#x73B0;&#x67D0;&#x4E2A;&#x64CD;&#x4F5C;&#xFF0C;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;&#x6CA1;&#x51FA;&#x73B0;&#x5F02;&#x5E38;&#xFF0C;&#x4EFB;&#x52A1;&#x5C31;&#x53EF;&#x4EE5;&#x5B8C;&#x6210;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;&#x51FA;&#x73B0;&#x5F02;&#x5E38;&#xFF0C;&#x5C06;&#x5F02;&#x5E38;&#x4ECE;&#x5F53;&#x524D;&#x4EE3;&#x7801;&#x5757;&#x6254;&#x51FA;&#x53BB;&#x5C1D;&#x8BD5;&#x89E3;&#x51B3;&#x5F02;&#x5E38;</span>

  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">1</span>:
      <span class="hljs-comment"># &#x89E3;&#x51B3;&#x65B9;&#x6848;1&#xFF1A;&#x7528;&#x4E8E;&#x5C1D;&#x8BD5;&#x5728;&#x6B64;&#x5904;&#x5904;&#x7406;&#x5F02;&#x5E38;&#x89E3;&#x51B3;&#x95EE;&#x9898;</span>

  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">2</span>&#xFF1A;
      <span class="hljs-comment"># &#x89E3;&#x51B3;&#x65B9;&#x6848;2&#xFF1A;&#x7528;&#x4E8E;&#x5C1D;&#x8BD5;&#x5728;&#x6B64;&#x5904;&#x5904;&#x7406;&#x5F02;&#x5E38;&#x89E3;&#x51B3;&#x95EE;&#x9898;</span>

  <span class="hljs-keyword">except</span> (&#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">1</span>,&#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">2.</span>..)
      <span class="hljs-comment"># &#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF1A;&#x9488;&#x5BF9;&#x591A;&#x4E2A;&#x5F02;&#x5E38;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7684;&#x5904;&#x7406;&#x65B9;&#x5F0F;</span>

  excpet:
      <span class="hljs-comment"># &#x89E3;&#x51B3;&#x65B9;&#x6848;&#xFF1A;&#x6240;&#x6709;&#x5F02;&#x5E38;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;</span>

  <span class="hljs-keyword">else</span>:
      <span class="hljs-comment"># &#x5982;&#x679C;&#x6CA1;&#x6709;&#x51FA;&#x73B0;&#x4EFB;&#x4F55;&#x5F02;&#x5E38;&#xFF0C;&#x5C06;&#x4F1A;&#x6267;&#x884C;&#x6B64;&#x5904;&#x4EE3;&#x7801;</span>

  <span class="hljs-keyword">finally</span>:
      <span class="hljs-comment"># &#x7BA1;&#x4F60;&#x6709;&#x6CA1;&#x6709;&#x5F02;&#x5E38;&#x90FD;&#x8981;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;</span>
</code></pre>
</li>
<li><h3 id="&#x5904;&#x7406;&#x8FC7;&#x7A0B;">&#x5904;&#x7406;&#x8FC7;&#x7A0B;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">try</span>:
      <span class="hljs-comment"># &#x5C1D;&#x8BD5;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x533A;&#x57DF;&#x3002;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;&#x6CA1;&#x6709;&#x9519;&#x8BEF;&#xFF0C;&#x90A3;&#x5C31;&#x6CA1;&#x5565;&#x4E8B;&#x4E86;&#xFF0C;&#x5219;&#x6267;&#x884C;else&#x533A;&#x57DF;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;&#x51FA;&#x73B0;&#x9519;&#x8BEF;&#xFF0C;&#x629B;&#x51FA;&#x9519;&#x8BEF;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#xFF0C;&#x7531;&#x4E0B;&#x9762;&#x7684;&#x5176;&#x4ED6;&#x5757;&#x5C1D;&#x8BD5;&#x63A5;&#x53D7;&#x9519;&#x8BEF;</span>

  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">1</span>:
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E00;&#x76F4;&#xFF0C;&#x90A3;&#x4E48;&#x5219;&#x5F53;&#x524D;&#x5757;&#x63A5;&#x6536;&#x9519;&#x8BEF;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5F53;&#x524D;&#x533A;&#x57DF;&#x7ED9;&#x51FA;&#x9519;&#x8BEF;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E0D;&#x4E00;&#x76F4;&#xFF0C;&#x5219;&#x5C06;&#x5F02;&#x5E38;&#x6254;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x68C0;&#x6D4B;</span>

  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">2</span>:
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E00;&#x76F4;&#xFF0C;&#x90A3;&#x4E48;&#x5219;&#x5F53;&#x524D;&#x5757;&#x63A5;&#x6536;&#x9519;&#x8BEF;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5F53;&#x524D;&#x533A;&#x57DF;&#x7ED9;&#x51FA;&#x9519;&#x8BEF;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E0D;&#x4E00;&#x76F4;&#xFF0C;&#x5219;&#x5C06;&#x5F02;&#x5E38;&#x6254;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x68C0;&#x6D4B;</span>

  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">3</span>:
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E00;&#x76F4;&#xFF0C;&#x90A3;&#x4E48;&#x5219;&#x5F53;&#x524D;&#x5757;&#x63A5;&#x6536;&#x9519;&#x8BEF;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5F53;&#x524D;&#x533A;&#x57DF;&#x7ED9;&#x51FA;&#x9519;&#x8BEF;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E0D;&#x4E00;&#x76F4;&#xFF0C;&#x5219;&#x5C06;&#x5F02;&#x5E38;&#x6254;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x68C0;&#x6D4B;</span>

  <span class="hljs-keyword">except</span> (&#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">4</span>&#xFF0C;&#x5F02;&#x5E38;&#x7C7B;&#x578B;<span class="hljs-number">5</span>&#xFF0C;...)
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x4EFB;&#x610F;&#x5B9A;&#x7C7B;&#x578B;&#x4E00;&#x76F4;&#xFF0C;&#x90A3;&#x4E48;&#x5219;&#x5F53;&#x524D;&#x5757;&#x63A5;&#x6536;&#x9519;&#x8BEF;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5F53;&#x524D;&#x533A;&#x57DF;&#x7ED9;&#x51FA;&#x9519;&#x8BEF;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x3002;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;try&#x5757;&#x6254;&#x51FA;&#x7684;&#x5F02;&#x5E38;&#x7C7B;&#x578B;&#x548C;&#x5F53;&#x524D;&#x6307;&#x5B9A;&#x7C7B;&#x578B;&#x4E0D;&#x4E00;&#x76F4;&#xFF0C;&#x5219;&#x5C06;&#x5F02;&#x5E38;&#x6254;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x4EE3;&#x7801;&#x5757;&#x68C0;&#x6D4B;</span>

  <span class="hljs-keyword">except</span>: <span class="hljs-comment">#&#x6240;&#x6709;&#x5F02;&#x5E38;</span>
      <span class="hljs-comment"># &#x5982;&#x679C;&#x5176;&#x4ED6;except&#x5757;&#x5747;&#x4E0D;&#x80FD;&#x63A5;&#x53D7;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48;&#x5219;&#x5F53;&#x524D;&#x5757;&#x63A5;&#x53D7;&#x5F02;&#x5E38;&#xFF0C;&#x5E76;&#x4E14;&#x8FDB;&#x884C;&#x5904;&#x7406;&#x5373;&#x53EF;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>

  <span class="hljs-keyword">else</span>:
      <span class="hljs-comment"># try&#x533A;&#x57DF;&#x4EE3;&#x7801;&#x6CA1;&#x6709;&#x4EFB;&#x4F55;&#x5F02;&#x5E38;&#xFF0C;&#x5219;else&#x533A;&#x57DF;&#x6267;&#x884C;&#xFF08;&#x975E;&#x5FC5;&#x987B;&#xFF09;</span>

  <span class="hljs-keyword">finally</span>:
      <span class="hljs-comment"># &#x65E0;&#x8BBA;&#x51FA;&#x73B0;&#x6216;&#x8005;&#x4E0D;&#x51FA;&#x73B0;&#x5F02;&#x5E38;&#xFF0C;&#x5F53;&#x524D;&#x5757;&#x90FD;&#x4F1A;&#x6267;&#x884C;</span>
</code></pre>
</li>
</ul>
<hr>
<h1 id="&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x9519;&#x8BEF;&#x548C;&#x81EA;&#x5B9A;&#x4E49;&#x629B;&#x51FA;&#x9519;&#x8BEF;">&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x9519;&#x8BEF;&#x548C;&#x81EA;&#x5B9A;&#x4E49;&#x629B;&#x51FA;&#x9519;&#x8BEF;</h1>
<ul>
<li><h3 id="&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x629B;&#x51FA;&#x64CD;&#x4F5C;">&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x629B;&#x51FA;&#x64CD;&#x4F5C;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">raise</span>  &#x5F02;&#x5E38;&#x5BF9;&#x8C61;
</code></pre>
</li>
<li><h3 id="&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x7C7B;">&#x7528;&#x6237;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x7C7B;</h3>
<pre><code class="lang-py">  <span class="hljs-class"><span class="hljs-keyword">class</span> &#x5F02;&#x5E38;&#x7C7B;&#x540D;<span class="hljs-params">(RuntimeError)</span>:</span>
      <span class="hljs-comment"># &#x5B9A;&#x4E49;&#x7528;&#x6237;&#x629B;&#x51FA;&#x81EA;&#x5B9A;&#x4E49;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#x65F6;&#x53EF;&#x4EE5;&#x5411;&#x5BF9;&#x8C61;&#x4E2D;&#x4F20;&#x5165;&#x7684;&#x5185;&#x5BB9;&#x4FE1;&#x606F;&#xFF08;&#x7531;&#x7528;&#x6237;&#x81EA;&#x5DF1;&#x51B3;&#x5B9A;&#xFF09;</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self,errormsg...)</span>:</span>
          <span class="hljs-comment"># &#x63A5;&#x6536;&#x7528;&#x6237;&#x521B;&#x5EFA;&#x5BF9;&#x8C61;&#x65F6;&#x4F20;&#x5165;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#xFF0C;&#x5E76;&#x4E14;&#x5B58;&#x5165;&#x5BF9;&#x8C61;&#xFF0C;&#x65B9;&#x4FBF;&#x540E;&#x671F;&#x4F7F;&#x7528;</span>
          self.errormsg = errormsg
          <span class="hljs-comment">#...</span>
      <span class="hljs-keyword">pass</span>
</code></pre>
</li>
<li><h3 id="&#x5728;tryexcept&#x4E2D;&#x63A5;&#x6536;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;">&#x5728;try..except&#x4E2D;&#x63A5;&#x6536;&#x5F02;&#x5E38;&#x5BF9;&#x8C61;</h3>
<pre><code class="lang-py">  <span class="hljs-keyword">try</span>:
      <span class="hljs-comment">#&#x5C1D;&#x8BD5;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x533A;&#x57DF;</span>
  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B; <span class="hljs-keyword">as</span> &#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#x53D8;&#x91CF;:
      <span class="hljs-comment">#&#x89E3;&#x51B3;&#x65B9;&#x6848;</span>
  <span class="hljs-keyword">except</span> &#x5F02;&#x5E38;&#x7C7B;&#x578B; <span class="hljs-keyword">as</span> &#x5F02;&#x5E38;&#x5BF9;&#x8C61;&#x53D8;&#x91CF;:
      <span class="hljs-comment">#&#x89E3;&#x51B3;&#x65B9;&#x6848;</span>
  <span class="hljs-comment">#....</span>
</code></pre>
</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../../home/8.面向对象/5.抽象类.html" class="navigation navigation-prev " aria-label="Previous page: 抽象类"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../../home/8.面向对象/7.模块和包.html" class="navigation navigation-next " aria-label="Next page: 模块和包"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../../gitbook/app.js"></script>

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
